let dataCont = JSON.parse(localStorage.getItem('dataCont'));
let date = new Date
console.log(date.toLocaleDateString());
console.log(dataCont);
$('#sel_3').attr('value', dataCont.d_id);
$('#sel_4').attr('value', dataCont.m_teacher);
$('#sel_8').val(dataCont.d_describe);
$('.textarea').next().children().html(dataCont.d_describe.length - 1);
$('#sel_6').attr('value', dataCont.m_id);
$('#sel_5').attr('value', dataCont.c_name);

function showSelCom() {
    $.ajax({
        url: '/class/showsel_department',
        success: (res) => {
            $('#sel_1').html(`<option value="${dataCont.d_name}" selected disabled class="sel_none">${dataCont.d_name}</option>`);
            $(res.data).each((index, item) => {
                $('#sel_1').append(`    
            <option value="${item.d_name}">${item.d_name}</option>`);
            })
        }
    })
}

function showSelCom2() {
    $.ajax({
        url: '/class/showsel_major',
        data: {
            val: dataCont.d_name
        },
        success: (res) => {
            console.log(res);
            $('#sel_2').html(`<option value="${dataCont.m_name}" selected disabled class="sel_none">${dataCont.m_name}</option>`);
            $(res.data).each((index, item) => {
                $('#sel_2').append(`    
        <option value="${item.m_name}">${item.m_name}</option>`);
            })
        }
    })
}
$('.textarea')[0].oninput = function() {
    $(this).next().children().html(this.value.length);
}

// 编辑班级
function orgRedact() {
    $('.btn_redact').click(function() {
        if (confirm('是否确定保存修改？')) {
            $.ajax({
                url: '/class/redact',
                method: 'post',
                data: {
                    m_id: $('#sel_6').val(), //专业ID
                    c_name: $('#sel_4').val(),
                    c_id: dataCont.c_id
                },
                success: (res) => {
                    if (res.error) {
                        console.log(res.msg);
                        alert('带*的内容必须填写!');
                    } else {
                        alert('修改成功!');
                        window.history.go(-1);
                    }
                }
            })
        }
    })
}